// 用户定义的类型
package main

import "fmt"

type user struct {
    name string
    email string
    ext int
    privileged bool
}

func assert(b bool) {
    if (!b) {
        panic("a panic here")
    }
}

func test1() {
    fmt.Println("run test1")
    var bill user
    assert(bill.name == "")
    assert(bill.privileged == false)

    bill2 := user {
        name: "Lisa",
        email: "lisa@email.com",
        ext: 123,
        privileged: true,
    }
    fmt.Println(bill2)

    bill3 := user {"Lisa", "lisa@email.com", 123, true}
    fmt.Println(bill3)
}

type admin struct {
    person user
    level string
}

func test2() {
    fmt.Println("run test2")
    fred := admin {
        person: user {
            name: "Lisa",
            email: "lisa@email.com",
            ext: 123,
            privileged: true,
        },
        level: "super",
    }
    fmt.Println(fred)
}

type duration int64

func test3() {
    fmt.Println("run test3")
    var d duration
    d = duration(1000)
    assert(d == 1000)

    var d2 duration
    // d2 = int64(1000) // error
    d2 = duration(1000)
    assert(d2 == 1000)
}

func main() {
    test1()
    test2()
    test3()
}
